package com.ty.web;

import com.ty.bean.Grade;
import com.ty.service.GradeService;
import com.ty.service.impl.GradeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 田野
 */
@WebServlet(urlPatterns = "/Educational/student/getGradeList")
public class GetGradeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 查询所有年级列表的方法
        GradeService service = new GradeServiceImpl();
        List<Grade> list = service.getList();
        // 测试用
        System.out.println("是否在数据库中查询并返回数据：" + list);
        req.setAttribute("glist", list);
        // 注意，以前是直接跳转到add.jsp，现在是先跳转到servlet之后再跳转到add.jsp页面  更改add.jsp页面
        req.getRequestDispatcher("add.jsp").forward(req,resp);
    }
}
